﻿using Manon.Admin.Web.ApplicationCore.Dtos.Settings;
using Manon.Admin.Web.ApplicationCore.Interfaces;
using Manon.Autofac;
using Manon.Core.Commons;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Manon.Admin.Web.Controllers
{
    public class ChanelController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Edit()
        {
            return View();
        }



        /// <summary>
        /// 获取栏目列表
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<List<GetChanelListTreeOutput>> GetChanelListTree()
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.GetChanelListTree();
            return result;
        }



        /// <summary>
        /// 获取栏目
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<GetChanelListTreeOutput> GetChanel(int Id)
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.GetChanel(Id);
            return result;
        }


        /// <summary>
        /// 保存栏目
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> SaveChanel([FromBody] SaveChanelInput Input)
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.SaveChanel(Input);
            return result;
        }


        /// <summary>
        /// 删除栏目
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> DeleteChanel(int Id)
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.DeleteChanel(Id);
            return result;
        }

        /// <summary>
        /// 删除栏目
        /// </summary>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<Result> SetChanelEnabled(int Id, bool Enabled)
        {

            var settingsService = Resolver.Resolve<ISettingsService>();
            var result = await settingsService.SetChanelEnabled(Id, Enabled);
            return result;
        }
    }
}
